﻿using System.Collections.Generic;
using System.IO;

namespace Nutilities.Net
{
    public class BinaryReaderUtility
    {
        public delegate T ReadListElement<out T>(BinaryReader reader);

        public static List<T> ReadList<T>(BinaryReader reader, ReadListElement<T> readCallback)
        {
            int length = reader.ReadInt32();
            List<T> list = new List<T>(length);
            for (int i = 0; i < length; i++)
            {
                list.Add(readCallback(reader));
            }
            return list;
        }
    }
}
